// index.ts
// 获取应用实例
import { requestGET } from '../../utils/service'
// const app = getApp<IAppOption>()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    showKeFu: false,
    reportList: [
      {
        title: '细胞营养均衡度检测检测检1213131231312',
        date: '2024-08-24',
        price: '399',
        status: 0,
      },
      {
        title: '细胞营养均衡度检测检测检1213131231312',
        date: '2024-08-24',
        price: '399',
        status: 1,
      },
      {
        title: '细胞营养均衡度检测检测检1213131231312',
        date: '2024-08-24',
        price: '399',
        status: 2,
      },
      {
        title: '细胞营养均衡度检测检测检1213131231312',
        date: '2024-08-24',
        price: '399',
        status: 3,
      }, {
        title: '细胞营养均衡度检测检测检1213131231312',
        date: '2024-08-24',
        price: '399',
        status: 0,
      }
      , {
        title: '细胞营养均衡度检测检测检1213131231312',
        date: '2024-08-24',
        price: '399',
        status: 0,
      }
    ]
  },

  onShow() {
    this.setData({ userInfo: wx.getStorageSync('userInfo') })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getMyReports()
  },

  // 获取我的报告
  getMyReports() {
    requestGET("reservation/queryAllReservation", {})
      .then((res: any) => {
        if (res.data.code == '200') {
          this.setData({
            reportList: res.data.data
          })
        } else {
          wx.showToast({
            title: '服务异常',
            icon: 'error',
            duration: 2000
          })
        }
      })
  },

  // 查看我的报告
  toSeeReport(e: any) {
    console.log(e.currentTarget.dataset.item)
    const item = e.currentTarget.dataset.item
    if (item.physicalExaminationStatus == '已检测') {
      let urlStr = ''
      if (item.physicalExaminationPackageId == 1) {
        urlStr = '/pages/reportDetail/index?reservationId='
      } else if (item.physicalExaminationPackageId == 3) {
        urlStr = '/pages/reportDetail3/index?reservationId='
      } else {
        urlStr = '/pages/reportDetails/index?reservationId='
      }
      const url = urlStr + item.reservationId + '&reservationDate=' + item.reservationDate + '&physicalExaminationPackageTitle=' + item.physicalExaminationPackageInfo.physicalExaminationPackageTitle
      wx.navigateTo({
        url: url,
      })
    }
  },

  // 跳转到分享界面
  share() {
    const url = '/pages/share/index'
    wx.navigateTo({
      url: url,
    })
  },
  // 跳转到修改个人信息界面
  editInfo() {
    const url = '/pages/editMyInfo/index'
    wx.navigateTo({
      url: url,
    })
  },
  // 跳转到预约界面
  jumpToReservation() {
    const url = '/pages/checkupPackageList/index'
    wx.navigateTo({
      url: url,
    })
  },
  // 关闭\打开 客服弹窗
  closeKeFu(e: any) {
    this.setData({ showKeFu: e.currentTarget.dataset.value == 'true' ? true : false })
  },
})
